﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;

public class EventTriggers : MonoBehaviour, IPointerClickHandler
{
    private UnityAction<PointerEventData> m_OnClick;
    public UnityAction<PointerEventData> OnClick
    {
        get => m_OnClick;
        set => m_OnClick = value;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        var components = ListPool<IPointerClickHandler>.Get();
        transform.GetComponents(components);
        foreach (var component in components)
        {
            if (!ReferenceEquals(component, this))
                component.OnPointerClick(eventData);
        }
        
        OnClick.Invoke(eventData);
    }
}
